package com.meirengu.webview.controller;

import com.meirengu.common.StatusCode;
import com.meirengu.controller.BaseController;
import com.meirengu.model.Result;
import com.meirengu.webview.service.SearchCreditCardService;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("SearchCreditCard")
@Controller
public class SearchCreditCardController extends BaseController {

    @Autowired
    SearchCreditCardService searchCreditCardService;

    Logger logger = LoggerFactory.getLogger(SearchCreditCardController.class);

    @RequestMapping(value = "findCredit", method = RequestMethod.GET)
    @ResponseBody
    public Result SearchCreditCard() {
        try {
            Integer count = searchCreditCardService.findCreditCard();
            return super.setResult(StatusCode.OK, count, StatusCode.codeMsgMap.get(StatusCode.OK));
        } catch (Exception e) {
            e.printStackTrace();
            String params = "";
            logger.error(">> SearchCreditCardController.SearchCreditCard throw exception: {} happens. params:{}.", ExceptionUtils.getFullStackTrace(e), params);
            return super.setResult(StatusCode.INTERNAL_SERVER_ERROR, null, StatusCode.codeMsgMap.get(StatusCode.INTERNAL_SERVER_ERROR));
        }
    }
}
